Imports System.Data.SqlClient
Imports ModuloAdministraciondeEnvios.Entity
Imports ModuloAdministraciondeEnvios.BusinessLogicLayer

Namespace DataAccessLayer

    Public Class DataCliente
        Inherits Cliente
        Implements ICliente




        Public Function AgregarCliente(ByVal Cliente As Cliente) As Boolean Implements ICliente.AgregarCliente


            Nombre = Cliente.Nombre
            Domicilio = Cliente.Domicilio
            CUIT = Cliente.CUIT
            Localidad = Cliente.Localidad



            Try

                Dim Conecta As New SqlConnection(StringConecta)
                Conecta.Open()
                Comando = New SqlCommand(StringComando, Conecta)

                Comando.CommandText = "Cliente_Insert"
                Comando.CommandType = CommandType.StoredProcedure

                Comando.Parameters.Add("@Nombre", SqlDbType.VarChar, 50, "Nombre").Value = Nombre
                Comando.Parameters.Add("@Domicilio", SqlDbType.VarChar, 50, "Domicilio").Value = Domicilio
                Comando.Parameters.Add("@CUIT", SqlDbType.VarChar, 13, "CUIT").Value = CUIT
                Comando.Parameters.Add("@Localidad", SqlDbType.Int, 4, "Localidad").Value = Localidad

                Comando.ExecuteNonQuery()

                MsgBox("Registro Grabado con Exito")

                Conecta.Close()
                Conecta.Dispose()

                Return True

            Catch ex As Exception

                MsgBox(ex.Message)

                Return False

            End Try


        End Function
        Public Function BorrarCliente(ByVal n As Integer) As Boolean Implements BusinessLogicLayer.ICliente.BorrarCliente

            Try

                Dim Conecta As New SqlConnection(StringConecta)
                Conecta.Open()
                Comando = New SqlCommand(StringComando, Conecta)
                Comando.CommandText = "Cliente_DeleteRow"
                Comando.CommandType = CommandType.StoredProcedure
                Comando.Parameters.Add("@IDCliente", SqlDbType.Int, 4, "IDCliente").Value = n
                Comando.ExecuteNonQuery()
                Conecta.Close()
                Conecta.Dispose()

                MsgBox("Borrado Registro " & n, MsgBoxStyle.Critical)

                Return True

            Catch ex As Exception

                MsgBox("No pudo por que " & ex.Message)
                Return False

            End Try

        End Function

        Public Function ModificarCliente(ByVal n As Integer, ByVal Cliente As Entity.Cliente) As Boolean Implements BusinessLogicLayer.ICliente.ModificarCliente

        End Function

    

        Public Function TraerRegistroClientePorCUIT(ByVal CUIT As String) As System.Data.DataSet Implements BusinessLogicLayer.ICliente.TraerRegistroClientePorCUIT


            Try

                Dim Conecta As New SqlConnection(StringConecta)
                Comando = New SqlCommand(StringComando, Conecta)
                Comando.CommandText = "Cliente_SelectRow_Por_CUIT"
                Comando.CommandType = CommandType.StoredProcedure


                Dim BuscarCUIT As SqlParameter = New SqlParameter("@CUIT", CUIT)
                BuscarCUIT.Direction = ParameterDirection.Input
                BuscarCUIT.DbType = DbType.String

                Comando.Parameters.Add(BuscarCUIT)

                Dim Adapter As SqlDataAdapter = New SqlDataAdapter(Comando)
                Dim Ds As DataSet = New DataSet(Comando.CommandText)

                Adapter.Fill(Ds)

                Return Ds

            Catch ex As Exception

                MsgBox("No pudo por que " & ex.Message)

                Return Ds

            End Try


        End Function
        Public Function TraerRegistroClientePorNombre(ByVal nombre As String) As System.Data.DataSet Implements BusinessLogicLayer.ICliente.TraerRegistroClientePorNombre


            Try

                Dim Conecta As New SqlConnection(StringConecta)
                Comando = New SqlCommand(StringComando, Conecta)
                Comando.CommandText = "Cliente_SelectRow_Por_Nombre"
                Comando.CommandType = CommandType.StoredProcedure


                Dim BuscarNombre As SqlParameter = New SqlParameter("@Nombre", nombre)
                BuscarNombre.Direction = ParameterDirection.Input
                BuscarNombre.DbType = DbType.String

                Comando.Parameters.Add(BuscarNombre)

                Dim Adapter As SqlDataAdapter = New SqlDataAdapter(Comando)
                Dim Ds As DataSet = New DataSet(Comando.CommandText)

                Adapter.Fill(Ds)

                Return Ds

            Catch ex As Exception

                MsgBox("No pudo por que " & ex.Message)

                Return Ds

            End Try





        End Function

        Public Function TraerRegistroCliente(ByVal IDCliente As Integer) As Entity.Cliente Implements BusinessLogicLayer.ICliente.TraerRegistroCliente

            Try

                Dim Conecta As New SqlConnection(StringConecta)
                Comando = New SqlCommand(StringComando, Conecta)
                Comando.CommandText = "Cliente_SelectRow"
                Comando.CommandType = CommandType.StoredProcedure


                Dim BuscarID As SqlParameter = New SqlParameter("@IDCliente", IDCliente)
                BuscarID.Direction = ParameterDirection.Input
                BuscarID.DbType = DbType.String

                Comando.Parameters.Add(BuscarID)

                Dim Adapter As SqlDataAdapter = New SqlDataAdapter(Comando)
                Dim Ds As DataSet = New DataSet(Comando.CommandText)

                Adapter.Fill(Ds)

                Dim Cliente As New Cliente

                Cliente.IDCliente = Ds.Tables(0).Rows(0).Item(0)
                Cliente.Nombre = Ds.Tables(0).Rows(0).Item(1)
                Cliente.Domicilio = Ds.Tables(0).Rows(0).Item(2)
                Cliente.Localidad = Ds.Tables(0).Rows(0).Item(3)
                Cliente.CUIT = Ds.Tables(0).Rows(0).Item(4)

                Return Cliente

            Catch ex As Exception

                MsgBox("No pudo por que " & ex.Message)

                Dim Cliente As New Cliente
                Return Cliente

            End Try





        End Function
    End Class

End Namespace
